<!--  -->
<template>
  <div class="table">
    <!-- 新增按钮 
    <el-button type="success" plain @click="dialogTableVisible = true"
      >新增 add</el-button><hr>-->

    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="dataForm.key"
          placeholder="输入所属用户"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="
        tableData.filter(
          (data) =>
            !search ||
            data.machineId.toLowerCase().includes(search.toLowerCase())
        )
      "
      stripe
      height="500"
      border
      style="width: 100%"
    >
      <el-table-column
        fixed
        prop="createAt"
        header-align="center"
        align="center"
        label="日期"
        width="200"
      >
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="temperature"
        label="温度"
        width="200"
      >
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="humidity"
        label="湿度"
        width="200"
      >
      </el-table-column>
      <el-table-column
        prop="machineId"
        header-align="center"
        align="center"
        label="机器id"
        width="120"
      >
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="machineName"
        label="机器名称"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="machinePosition"
        header-align="center"
        align="center"
        label="机器位置"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        label="所属用户"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="department"
        header-align="center"
        align="center"
        label="所属部门"
        width="120"
      >
      </el-table-column>
      <el-table-column header-align="center" align="center" width="200">
        <template slot="header" slot-scope="scope">
          <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"
          /><span @change="h(scope.$index)"></span>
        </template>
        <template slot-scope="scope">
          <!-- <el-button
            type="success"
            icon="el-icon-edit"
            circle
            @click="() => handleEdit(scope.$index, scope.row)"
          >
          </el-button> -->
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="() => handleDelete(scope.$index, scope.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="172"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>

    <!-- 编辑对话框 -->
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="temhumform">
        <el-form-item label="温度">
          <el-input
            v-model="temhumform.temperature"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="湿度">
          <el-input v-model="temhumform.humidity" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="湿度">
          <el-input
            v-model="temhumform.machineId"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="() => editTemhum(temhumform)"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      dataForm: {
        key: "",
      },
      temhumform: {
        id: 0,
        temperature: 0,
        humidity: 0,
        machineId: "",
        createAt: "",
        machineName: "",
        machinePosition: "",
        department: "",
        userId: "",
      },
      tableData: [],
      search: "",
      dialogTableVisible: false,
      dialogFormVisible: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      selectionDataList: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getTableData() {
      this.$http({
        url: this.$http.adornUrl("/monitormanage/temhum/list/all"),
        method: "get",
      }).then(({ data }) => {
        console.log(data.page.list);
        this.tableData = data.page.list;
      });
    },
    // 点击修改按钮
    handleEdit(index, row) {
      console.log(index, row, "edit");
      this.temhumform.id = row.id;
      this.dialogFormVisible = true;
    },
    // 点击修改中的确定—— —— 修改表单
    editTemhum(temhumform) {
      console.log("提交了修改表单", temhumform);
      // 传数据
      this.dialogFormVisible = false;
    },
    // 删除
    handleDelete(index, row) {
      console.log(index, row, "delete");
      var ids = [row.id];
      this.$confirm("是否删除此日志?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/monitormanage/temhum/delete"),
            method: "post",
            data: this.$http.adornData(ids, false),
          }).then(({ data }) => {
            if (data.code != 500) {
              console.log("删除成功！！", ids);
              // 这里就可以去实现echart实时刷新
              // 重新加载页面
              this.getTableData();
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.getTableData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
</style>